<template>
	<view class="home">
		<view class="list" v-for="(item,index) in List" :key="index" @click="detail(item.id)">
			<image :src="item.image" class="list_img"></image>
			<view class="list_meun">
				<view class="list_name">{{item.title}}</view>
				<view class="list_userInfo">
					<view class="list_userleft">
						<view class="">
							<image :src="item.sponsor_logo" mode="" class="list_user_img"></image>
						</view>
						<view class="list_userInfo_view">
							<view class="list_user_name">{{item.sponsor_title ? item.sponsor_title : '微信用户'}}</view>
							<view class="list_user_dect">活动评选</view>
						</view>
					</view>
					<view class="list_usernum">
						{{item.fwl}}次浏览
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	
	import {listAPI} from "@/api/home"
	export default {
		data() {
			return {
				List:[],
				user:[],
				scrollHeight:0,
				currentPage: 0, // 当前页数
				allPage: 0, // 总页数，初始值设置为0
			}
		},
		mounted() {
			
		},
		onShow() {
			this.getList()
		},
		
		methods:{
			getList(){
				var that = this
				uni.showLoading({
					title:'加载中',
				})
				var parems = {
					page:1
				}
				listAPI(parems).then(res =>{
					if(res.code == 1){
						uni.hideLoading()
						that.List = res.data.data
						that.currentPage = res.data.current_page
						that.allPage = res.data.last_page
					}else{
						uni.showToast({
							title:res.msg,
							icon:'none',
						})
					}
				})
				.catch(res =>{
					uni.hideLoading()
				})
			},
			detail(data){
				uni.navigateTo({
					url:'./details?id=' + data
				})
			}
		},
		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom: function () {
			var that = this
			var currentPage = that.currentPage;
			var allPage = that.allPage;
			// 获取之前的数据
			var ListBefore = that.List;
			// 页数加1
			currentPage++;
			// 判断当前页数是否大于总页数
			if (currentPage <= allPage) {
				uni.showLoading({
					title:'加载中',
				})
				var parems = {
					page:currentPage
				}
				listAPI(parems).then(res =>{
					if(res.code == 1){
						uni.hideLoading()
						var array = res.data.data
						that.List = ListBefore.concat(array),
						that.currentPage = res.data.current_page
						that.allPage = res.data.last_page
					}else{
						uni.showToast({
							title:res.msg,
							icon:'none',
						})
					}
				})
				.catch(res =>{
					uni.hideLoading()
				})
			} else {
				uni.showToast({
					title: '没有更多数据',
					icon: 'none'
				})
			}
		},
		
	}
</script>

<style lang="scss">
	page{
		background: #f6f6f6 !important;
	}
	.home{
		display: flex;
		align-items: center;
		flex-direction: column;
		justify-content: center;
		padding: 0 30rpx 30rpx 30rpx;
		.list{
			width: 100%;
			margin-top: 20rpx;
		}
		.list_meun{
			background: #fff;
			padding:20rpx 25rpx;
		}
		.list_img{
			width: 100%;
			height: 300rpx;
			border-radius: 10rpx;
			background: #fff;
		}
		.list_name{
			font-size: 30rpx;
			color: #303133;
			font-weight: bold;
			letter-spacing: 2rpx;
			margin-bottom: 20rpx;
			word-break:break-all;
			display:-webkit-box;
			-webkit-line-clamp:2; //这里写的数字是几就是超过几行剩余的显示省略号
			-webkit-box-orient:vertical;
			overflow:hidden;
		}
		.list_userInfo{
			display: flex;
			align-items: center;
			justify-content: space-between;
		}
		.list_userleft{
			display: flex;
			align-items: center;
		}
		.list_user_img{
			width: 70rpx;
			height: 70rpx;
			border-radius: 50%;
			background: #c0c4cc;
		}
		.list_userInfo_view{
			margin-left: 20rpx;
		}
		.list_user_name{
			font-size: 28rpx;
			color: #303133;
			font-weight: bold;
			letter-spacing: 1rpx;
		}
		.list_user_dect{
			font-size: 24rpx;
			color: #c0c4cc;
			letter-spacing: 1rpx;
			margin-top: 10rpx;
		}
		.list_usernum{
			font-size: 26rpx;
			color: #303133;
			font-weight: bold;
		}
	}
</style>
